package marksys.free.com.marksys.ui.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import marksys.free.com.marksys.R;

public class CardPagerViewAdapter extends PagerAdapter {
    ImageView iv_img;
    ImageView delete_img;
    private List<PhotoEntity> mData;
    private Context context;
    private CallbackDeleteInfo callbackDeleteInfo;

    public CardPagerViewAdapter(Context context, List<PhotoEntity> list) {
        this.context = context;

        this.mData = list;

    }

    @Override
    public int getCount() {
        return mData.size();
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, int position) {
        View view = LayoutInflater.from(container.getContext())
                .inflate(R.layout.item_coverflow, container, false);
        container.addView(view);
        view.setTag(position);
        iv_img = view.findViewById(R.id.image);
        delete_img = view.findViewById(R.id.delete);
        delete_img.setVisibility(View.INVISIBLE);

        final int select = position;

        Glide.with(context).load(mData.get(select).path).into(iv_img);


        return view;
    }

    @Override
    public int getItemPosition(Object object) {
        // 最简单解决 notifyDataSetChanged() 页面不刷新问题的方法
        return POSITION_NONE;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
//        int select = position < mData.size() ? position : (position % mData.size());

    }

    public CallbackDeleteInfo getCallbackDeleteInfo() {
        return callbackDeleteInfo;
    }

    public void setCallbackDeleteInfo(CallbackDeleteInfo callbackDeleteInfo) {
        this.callbackDeleteInfo = callbackDeleteInfo;
    }

}
